package coreAuction;



public class Item implements Comparable<Item> {
	private String itemID;
	private String description;
	private Bid latestBid;
	
	public Item(String id, String desc){
		itemID = id;
		description = desc;
		latestBid = null;
	}
	
	public String getItemID() { return itemID; }
	
	public String getDescription () { return description; }
	
	public Bid getBid() { return latestBid; }
	 
	public String getItemReport() {
		String report = String.format("%-8s",itemID) + String.format("%-20s",description) ;
		if (latestBid == null) {
			report += "No bids made for this item\n";
		}
		else {
			report += "LATEST BID by cust id ";
			report += String.format("%-6s", latestBid.getBidCust().getCustID());
			report += String.format("%6.2f", latestBid.getBidMoney());
			report += "\n";

		}
		return report;
	}
	//////not used yet
	public int compareTo (Item other) {
		return itemID.compareTo(other.itemID);
	}
	///not used yet
	public boolean equals (Item other) {
		return itemID.equals(other.itemID);
	}
	
	//returns superceded bid
	public Bid addBid(Bid b) {
		Bid superceded = null;
		//if this is the first bid for this item
		if (latestBid == null ) {
			latestBid = b;
			b.setWinningBid();
		}
		//if bid is higher than prev
		else if (latestBid.getBidMoney() < b.getBidMoney()   ) {
			latestBid.setSuperceded();
			superceded = latestBid;
			latestBid = b;
			b.setWinningBid();
		}
		else {
			b.setFailed();
		}
		return superceded;
        
	}
	
	

}
